<?php
class NodeAction extends CommonAction {


    function index(){
        $node=M("Node");
        import("ORG.Util.Page");// 导入分页类
        $count=$node->count();
        $Page= new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->setConfigArray(array('header'=>'条操作','prev'=>'<input type="button" value="<<<">','next'=>'<input type="button" value=">>>">','first'=>'首页','last'=>'尾页','theme'=>' %totalRow% %header% %nowPage%/%totalPage% 页   %first% %prePage% %upPage%   <span style="color: red;background-color: #7fffd4;">%linkPage%</span>   %downPage% %nextPage% %end%'));
        $show=$Page->show();//分页显示输出
        $list=$node->limit($Page->firstRow.",".$Page->listRows)->select();
        $this->assign("list",$list);
        $this->assign('page',$show);// 赋值分页输出
        $this->display();
    }


    function modify(){
        if(!empty($_GET['id'])){
            $node=M("Node");
            if($list=$node->find($_GET['id'])){
                $this->assign("list",$list);
                $this->display();
            }else{
                $this->error("需要编辑的节点已经不存在了！");
            }
        }
    }


    function update(){
        $node=D("Node");
        if($node->create()){
            $node->save();
            $this->redirect("index");
        }else{
            $this->error("创建节点失败！");
        }
    }


    function add(){
        $this->display();
    }


    function insert(){
        $node=D("Node");
        if($node->create()){
            if($node->add()){
                $this->redirect("index");
            }else{
                $this->error("新增操作失败!");
            }
        }
    }

    function delete(){
        if(!empty($_GET['id'])){
            $node=M("Node");
            if($node->delete($_GET['id'])){
                $this->ajaxReturn("","删除成功！",1);
            }else{
                $this->ajaxReturn("","删除失败",0);
            }
        }
    }
}